package com.yungu.swift.system.finance.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.mapper.IMapper;
import com.yungu.swift.base.model.PageVo;
import com.yungu.swift.base.model.api.ApiPageParam;
import com.yungu.swift.base.service.impl.BaseServiceImpl;
import com.yungu.swift.system.finance.dao.FinanceActualFlowMapper;
import com.yungu.swift.system.finance.model.dto.FinanceActualFlowDto;
import com.yungu.swift.system.finance.model.param.AdminRechargeInvoicePageParam;
import com.yungu.swift.system.finance.service.FinanceActualFlowService;
import com.yungu.swift.utils.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * <p>
 * 财务流水业务逻辑处理接口实现类
 *
 * @author xiuyin.cui - Generate
 * @version 1.1.0-SNAPSHOT
 * @since 2019-04-25 13:50
 */
@Service
public class FinanceActualFlowServiceImpl extends BaseServiceImpl<FinanceActualFlowDto> implements FinanceActualFlowService {

    @Autowired
    private FinanceActualFlowMapper financeActualFlowMapper;

    @Override
    protected IMapper<FinanceActualFlowDto> getMapper() {
        return financeActualFlowMapper;
    }

    @Override
    public ResponseData<List<FinanceActualFlowDto>> queryBillFlow(ApiPageParam apiPageParam) {
        PageBounds pageBounds = new PageBounds(apiPageParam.getNowPage(), apiPageParam.getPageSize());
        Map<String, Object> paramMap = MapUtils.build(2);
        paramMap.put("passengerUuid", apiPageParam.getUserUuid());
        return ResponseData.buildSuccessResponse(financeActualFlowMapper.queryPageCanBill(paramMap, pageBounds));
    }

    @Override
    public ResponseData<PageVo<FinanceActualFlowDto>> rechargeInvoicePage(AdminRechargeInvoicePageParam pageParam) {
        PageBounds pageBounds = new PageBounds(pageParam.getPageNum(), pageParam.getPageSize());
        Set<String> orderIds = org.springframework.util.StringUtils.commaDelimitedListToSet(pageParam.getOrderUuids());
        PageList<FinanceActualFlowDto> pageList = financeActualFlowMapper.rechargeInvoicePage(orderIds, pageBounds);
        PageVo<FinanceActualFlowDto> pageVo = new PageVo(pageParam.getPageNum(), pageParam.getPageSize(),
                pageList.getPaginator().getTotalCount());
        pageVo.setItems(pageList);
        return ResponseData.buildSuccessResponse(pageVo);
    }
}